import datetime
import json
from pprint import pprint
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
plotly.tools.set_credentials_file(username='zb1261096', api_key='skaEiEgl40N5Rs6LCgO9')
import requests
import warnings
warnings.filterwarnings('ignore')
import numpy as np
import matplotlib.pyplot as plt
import mpld3
mpld3.enable_notebook()
from matplotlib.widgets import Slider, Button, RadioButtons
from matplotlib import interactive
interactive(True)
import IPython
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:95% !important; }</style>"))
%%html
<style>
.output_wrapper, .output {
height:auto !important;
max-height:2400px; /* your desired max-height here */
}
.output_scroll {
box-shadow:none !important;
webkit-box-shadow:none !important;
}
</style>
#df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/Mining-BTC-180.csv')
ques_data = json.load(open('autismema-question_sets-export.json'))
user_data = json.load(open('Zachery McCann_autismema-ivptwbfU29S3Bp09NUbx08JoLMl1-export.json'))
q_set = ques_data['general']
q_id_map = {}
all_question_list = []
index = 0
for ques in q_set['question']:
if ques != None:
all_question_list.append(ques["text"])
q_id_map[ques["id"]] = index
index = index + 1
all_ema = [[],[],[]]
all_ema[0].append("Question")
all_ema[1].append("Question")
all_ema[2].append("Question")
all_answer_list = [[],[],[]]
all_answer_list[0].append(all_question_list)
all_answer_list[1].append(all_question_list)
all_answer_list[2].append(all_question_list)
for ema in user_data['ema']:
if ema != None:
answer_list = ["N/A"] * len(all_question_list)
for answer in ema['usersAllEMAAnswers'].values():
i = q_id_map[answer['questionId']]
answer_list[i] = answer['answer']
d = datetime.datetime.fromtimestamp(float(ema["timeUTC"])/1000.0).strftime("%Y-%m-%d <br> %H:%M")
if ema["questionSet"] == "general":
all_answer_list[0].append(answer_list)
all_ema[0].append("Ema: <br>"+d)
elif ema["questionSet"] == "general2":
all_answer_list[1].append(answer_list)
all_ema[1].append("Ema: <br>"+d)
elif ema["questionSet"] == "general3":
all_answer_list[2].append(answer_list)
all_ema[2].append("Ema: <br>"+d)
else:
print("")
c_width = [1] * len(all_ema[0])
c_width[0] = 2
table = go.Table(
columnwidth=c_width,
header=dict(
height = 50,
values=all_ema[0],
font=dict(size=18),
# line = dict(color='rgb(50, 50, 50)'),
align = 'left',
#fill = dict(color='#d562be'),
),
cells=dict(
values=all_answer_list[0],
font=dict(size=14),
height = 40,
line = dict(color='rgb(50, 50, 50)'),
align = 'left',
fill = dict(color='#f5f5fa')
)
)
py.iplot([table], filename='EMA 1')
c_width = [1] * len(all_ema[1])
c_width[0] = 2
table = go.Table(
columnwidth=[2, 1, 1,1, 1, 1],
header=dict(
height = 50,
values=all_ema[1],
font=dict(size=18),
# line = dict(color='rgb(50, 50, 50)'),
align = 'left',
#fill = dict(color='#d562be'),
),
cells=dict(
height = 40,
font=dict(size=14),
values=all_answer_list[1],
line = dict(color='rgb(50, 50, 50)'),
align = 'left',
fill = dict(color='#f5f5fa')
)
)
py.iplot([table], filename='EMA 2')
c_width = [1] * len(all_ema[2])
c_width[0] = 2
table = go.Table(
columnwidth=c_width,
header=dict(
values=all_ema[2],
font=dict(size=18),
height = 50,
# line = dict(color='rgb(50, 50, 50)'),
align = 'left',
#fill = dict(color='#d562be'),
),
cells=dict(
font=dict(size=14),
height = 40,
values=all_answer_list[2],
line = dict(color='rgb(50, 50, 50)'),
align = 'left',
fill = dict(color='#f5f5fa')
)
)
py.iplot([table], filename='EMA 3')
x_list = []
y_list = []
light_dict = {}
for key, value in sorted(user_data['sensors']['light'].items()):
d = datetime.datetime.fromtimestamp(float(key)/1000.0)
x_list.append(d)
y_list.append(float(value))
light_dict[d] = float(value)
plt.rcParams["figure.figsize"] = (22,18)
plt.xlim(x_list[0],x_list[600])
plt.plot(x_list,y_list)
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()
#axes.set_xlim([min(x_list),max(x_list)])
#axes.set_ylim([min(y_list),max(y_list)])
plt.show()
x_list_noise = []
y_list_noise = []
noise_dict = {}
for key, value in sorted(user_data['sensors']['noise'].items()):
d = datetime.datetime.fromtimestamp(float(key)/1000.0)
x_list_noise.append(d)
y_list_noise.append(float(value))
noise_dict[d] = float(value)
#plt.yticks(np.arange(min(y_list),max(y_list), 3000))
plt.rcParams["figure.figsize"] = (22,18)
#plt.axis([x_list[0],x_list[200],0,max(y_list)+1000])
plt.xlim(x_list_noise[0],x_list_noise[300])
plt.plot(x_list_noise,y_list_noise)
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()
#my_xticks = ['a', 'b', 'c', 'd']
#plt.xticks(x, my_xticks)
plt.show()
r = requests.get('https://api.fitbit.com/1/user/-/activities/heart/date/2018-02-21/1d/1sec/time/00:00/16:00.json', headers={'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2RzdHVk4iLCJhdWQiOiIyMkNNQ0giLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJzY29wZXMiOiJyc29jIHJhY3QgcnNldCBybG9jIHJ3ZWkgcmhyIHJudXQgcnBybyByc2xlIiwiZXhwIjoxNTIyMTE0OTUxLCJpYXQiOjE1MTk1MjI5NTF9.0inpK-NFY9GvHkKIlAPbkqh5ZRhOlXlHx_-Z9t9l6xU'})
heart_rate_json = r.json()
x_list = []
y_list = []
heart_rate_dict = {}
date = "2018-02-15"
for answer in heart_rate_json['activities-heart-intraday']['dataset']:
d = datetime.datetime.strptime(date+" "+answer['time'], '%Y-%m-%d %H:%M:%S')
x_list.append(d)
y_list.append(int(answer['value']))
heart_rate_dict[d] = int(answer['value'])
plt.rcParams["figure.figsize"] = (22,18)
#plt.axis([x_list[0],x_list[200],0,max(y_list)+1000])
plt.xlim(x_list[0],x_list[200])
plt.plot(x_list,y_list)
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()
#my_xticks = ['a', 'b', 'c', 'd']
#plt.xticks(x, my_xticks)
plt.show()
print("N/A")
max_val = max(y_list_noise)
norm_y_list_noise = [float(i)*100/max_val for i in y_list_noise]
plt.figure(1)
ax1 = plt.subplot(211)
plt.xlim(x_list_noise[0],x_list_noise[200])
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()
plt.plot(x_list_noise,norm_y_list_noise)
plt.subplot(212,sharex = ax1)
plt.xlim(x_list[0],x_list[200])
plt.ylim(0,200)
plt.plot(x_list,y_list)
# beautify the x-labels
plt.gcf().autofmt_xdate()
axes = plt.gca()